<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>setTimeout 延迟执行代码，只执行一次</p>
    <button onclick="lanch()">发射🚀</button>
    <button onclick="cancel()">取消</button>
    <script>
        var timer = null;
        function lanch() {
            timer = setTimeout(function() {
                console.log('长征2号-丙运载火箭，成功发射');
            }, 3000);
        }
        function cancel() {
            clearTimeout(timer)
        }
    </script>
</body>
</html>